package business.parser

import dao.Word
import groovy.sql.DataSet
import groovy.sql.Sql
import org.apache.log4j.Logger;
import java.util.regex.Pattern;
import business.database.*;

class CorpWords {
	
	static main(args) {
		Database.getInstance().setSqlite("C:\\pruebas\\CorpCoding\\MaescorpNana\\wos_estatPalabras_estatGrupos.db")
	
	CorpWords p = new CorpWords();
	p.fillCorpWordTable();
	
	Database.getInstance().closeSqlite();
	}
	
	
	/**
	 * Rellena la tabla corpword, que contiene cada corp ligado a sus palabras y grupos. Se utiliza principalmente para
	 * hacer busquedas sobre los corps sin tener en cuenta los grupos
	 */
	public void fillCorpWordTable() {
		Database.getInstance().startTransaction_Sqlite()
		
		Database.getInstance().sqlite.eachRow("select idcorp from corp", {
			
			int idCorp = it[0]
			System.out.println(idCorp);
			Database.getInstance().sqlite.eachRow("select gw.idword, gw.idgroup from groupedword gw inner join corpgroup cg on cg.idgroup = gw.idgroup where cg.idcorp = ${idCorp} and cg.type >= 0 order by cg.position, gw.idgroup, gw.ordernum" , {
				int idword = it[0]
				int idgroup = it[1]
				
				Database.getInstance().sqlite.execute("INSERT INTO corpword VALUES (${idCorp},${idword},${idgroup})")
			})
			
		})
		
		Database.getInstance().endTransaction_Sqlite()
	}
	
	
	
	
}
